//
//  ViewController.m
//  UIScrollView
//
//  Created by blue on 15-12-22.
//  Copyright (c) 2015年 ZX. All rights reserved.
//

#import "ViewController.h"

@interface ViewController () <UIScrollViewDelegate>
{
    UIScrollView *scroll;
    UIPageControl * pc;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    scroll = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:scroll];
    
    
    NSArray * arr = [[NSBundle mainBundle]URLsForResourcesWithExtension:@"jpeg" subdirectory:nil];
    [arr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
    {
        UIImage * img = [UIImage imageNamed:[obj lastPathComponent]];
        CGRect rect = self.view.bounds;
        rect.origin.x = idx * rect.size.width;
        UIImageView *iv = [[UIImageView alloc]initWithFrame:rect];
        iv.image = img;
        [scroll addSubview:iv];
        scroll.delegate = self;
        }];
     scroll.contentSize = CGSizeMake(self.view.frame.size.width * arr.count, self.view.frame.size.height);
    //翻整页
    scroll.pagingEnabled = YES;
    scroll.bounces = NO;
    
    //点
    pc = [[UIPageControl alloc]initWithFrame:CGRectZero];
    pc.numberOfPages = 6;
    pc.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height - 40);
    [self.view addSubview:pc];
}

//点滑动
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"end decelerating! %f",scrollView.contentOffset.x);
    CGFloat page = scrollView.contentOffset.x / self.view.frame.size.width;
    pc.currentPage = (int)page;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
